﻿using B.S.Shop.Application.Command;
using B.S.Shop.Domain;
using B.S.Shop.ErrorCode;
using B.S.Shop.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Shop.Application.Commandhandler
{
    public class OderIsShowQueryCommandHandler : IRequestHandler<OderIsShowQueryCommand, APIResult<List<OrderClass>>>
    {
        public OderIsShowQueryCommandHandler(IBaseRepository<OrderClass> orderRepository)
        {
            OrderRepository = orderRepository;
        }

        public IBaseRepository<OrderClass> OrderRepository { get; }

        public async Task<APIResult<List<OrderClass>>> Handle(OderIsShowQueryCommand request, CancellationToken cancellationToken)
        {
            var path = OrderRepository.GetAll().Where(a => a.isShow == true);
            if(path==null)
            {
                return new APIResult<List<OrderClass>>
                {
                    Code = ResultCode.success,
                    Mag = "",
                    data = null
                };
            }
            else
            {
                return new APIResult<List<OrderClass>>
                {
                    Code = ResultCode.success,
                    Mag = "",
                    data = path.ToList()
                };
            }
        }
    }
}
